/**
 * 
 */
package net.looker.data;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;

import net.looker.config.ConfigManager;
import net.looker.util.Html;
import net.looker.util.MD5;
import net.looker.util.Tag;
import net.looker.util.URLUtils;

/**
 * @author solosky
 *
 */
public class News 
{
	/**
	 * 新闻编号
	 */
	protected String newsHash;
	/**
	 * 新闻URL
	 */
	protected String url;
	/**
	 * 新闻标题
	 */
	 protected String title;
	/**
	 * 标题连接文字
	 */
	 protected String anchor;
	 /**
	 * 新闻作者
	 */
	 protected String author;
	/**
	 * 新闻所属分类
	 */
	 protected Category category;
	 
	/**
	 * 新闻发布时间
	 */
	 protected Date date;

	/**
	 * 新闻简介，去掉了html标签，并截取前xx个字符
	 */
	protected String intro;
	/**
	 * 新闻正文，去掉了HTML标签，但保留下来了p,br,img,a 等标记
	 */
	protected String brief;
	
	/**
	 * 新闻正文，没去掉HTML标签，但替换了新闻正文中的连接
	 */
	protected String original;
	
	/**
	 * 新闻正文，从网页中提取出来，没有进行任何处理
	 */
	protected String content;
	
	/**
	 * 新闻正文hash
	 */
	protected String contenthash;
	
	/**
	 * 新闻所包含的文件类型
	 */
	protected int image;
	protected int audio;
	protected int video;
	protected int doc;
	protected int zip;
	protected int other;
	
	/**
	 * 新闻所有的附件数目
	 */
	protected int media;
	
	/**
	 * 新闻缩略图
	 * 为一URLhash
	 */
	protected String thumb;
	
	/**
	 * 新闻的标签
	 */
	protected String tag;
	
	/**
	 * 新闻文件列表
	 */
	protected ArrayList <Media> mediaList;
	
	 /**
	  * 新闻原始的HTML
	  */
	 protected String source;

	 
	/**
	 * @return the image
	 */
	public int getImage() {
		return image;
	}

	/**
	 * @param image the image to set
	 */
	public void setImage(int image) {
		this.image = image;
	}

	/**
	 * @return the audio
	 */
	public int getAudio() {
		return audio;
	}

	/**
	 * @param audio the audio to set
	 */
	public void setAudio(int audio) {
		this.audio = audio;
	}

	/**
	 * @return the video
	 */
	public int getVideo() {
		return video;
	}

	/**
	 * @param video the video to set
	 */
	public void setVideo(int video) {
		this.video = video;
	}

	/**
	 * @return the doc
	 */
	public int getDoc() {
		return doc;
	}

	/**
	 * @param doc the doc to set
	 */
	public void setDoc(int doc) {
		this.doc = doc;
	}

	/**
	 * @return the zip
	 */
	public int getZip() {
		return zip;
	}

	/**
	 * @param zip the zip to set
	 */
	public void setZip(int zip) {
		this.zip = zip;
	}

	/**
	 * @return the other
	 */
	public int getOther() {
		return other;
	}

	/**
	 * @param other the other to set
	 */
	public void setOther(int other) {
		this.other = other;
	}

	/**
	 * @return the media
	 */
	public int getMedia() {
		return media;
	}

	/**
	 * @param media the media to set
	 */
	public void setMedia(int media) {
		this.media = media;
	}
	/**
	 * 
	 */
	public News() 
	{
		mediaList = new ArrayList<Media>();
	}

	/**
	 * 返回urlHash
	 */
	public String getNewsHash() 
	{
		if (newsHash==null)
			newsHash = URLUtils.hash(url);
		return newsHash;
	}
	
	/**
	 * @return the url
	 */
	public String getUrl()
	{
		return url;
	}

	/**
	 * @param url the url to set
	 */
	public void setUrl(String url)
	{
		this.url = url;
	}

	/**
	 * @param tag the tag to set
	 */
	public void setTag(String tag) {
		this.tag = tag;
	}

	/**
	 * @return the title
	 */
	public String getTitle()
	{
		String titleType = category.getSiteConfig().get("news.title");
		if (titleType!=null && titleType.equals("anchor"))
			return anchor;
		else
			return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title)
	{
		this.title = title;
	}

	/**
	 * @return the anchor
	 */
	public String getAnchor()
	{
		return anchor;
	}

	/**
	 * @param anchor the anchor to set
	 */
	public void setAnchor(String anchor)
	{
		this.anchor = anchor;
	}

	/**
	 * @return the author
	 */
	public String getAuthor()
	{
		return author;
	}

	/**
	 * @param author the author to set
	 */
	public void setAuthor(String author)
	{
		this.author = author;
	}
	

	/**
	 * @return the date
	 */
	public Date getDate()
	{
		return date;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(Date date)
	{
		this.date = date;
	}
	
	/**
	 * @return the fullcontent
	 */
	public String getContent()
	{
		return content;
	}

	/**
	 * @param fullcontent the fullcontent to set
	 */
	public void setContent(String content)
	{
		this.content = content;
		this.intro   = Html.stripTags(content);
		this.tag     = Tag.exactTag(intro);
		this.contenthash = URLUtils.hash(content);
	}

	/**
	 * @return the cleancontent
	 */
	public String getIntro()
	{
		return intro;
	}

	/**
	 * @param cleancontent the cleancontent to set
	 */
	public void setIntro(String intro)
	{
		this.intro = intro;
	}



	/**
	 * @return the category
	 */
	public Category getCategory() {
		return category;
	}

	/**
	 * @param category the category to set
	 */
	public void setCategory(Category category) {
		this.category = category;
	}

	/**
	 * @return the tag
	 */
	public String getTag()
	{
		return tag;
	}



	/**
	 * @return the brief
	 */
	public String getBrief() {
		return brief;
	}

	/**
	 * @param brief the brief to set
	 */
	public void setBrief(String brief) {
		this.brief = brief;
	}

	/**
	 * @return the original
	 */
	public String getOriginal() {
		return original;
	}

	/**
	 * @param original the original to set
	 */
	public void setOriginal(String original) {
		this.original = original;
	}

	/**
	 * @return the thumb
	 */
	public String getThumb() {
		return thumb;
	}

	/**
	 * @param thumb the thumb to set
	 */
	public void setThumb(String thumb) {
		this.thumb = thumb;
	}

	/**
	 * @return the source
	 */
	public String getSource() {
		return source;
	}

	/**
	 * @param source the source to set
	 */
	public void setSource(String source) {
		this.source = source;
	}


	/**
	 * @return the mediaList
	 */
	public ArrayList<Media> getMediaList() {
		return mediaList;
	}

	/**
	 * @param mediaList the mediaList to set
	 */
	public void setMediaList(ArrayList<Media> mediaList) {
		this.mediaList = mediaList;
	}

	/**
	 * @return the contenthash
	 */
	public String getContentHash() {
		return contenthash;
	}

	/**
	 * @return the contenthash
	 */
	public String getContenthash() {
		return contenthash;
	}

	/**
	 * @param contenthash the contenthash to set
	 */
	public void setContenthash(String contenthash) {
		this.contenthash = contenthash;
	}

	public String toString()
	{
		return getTitle()+'-'+getUrl();
	}

}
